package Ep06_BinaryTree.BT8_0101;

import Ep06_BinaryTree.TreeNode;

/**
 * @author Jimmy Zhan WORKSTATION
 * @date 2023/4/25 11:14
 * 说明：0101 对称二叉树
 * 遍历顺序：后序遍历
 * 思路：同时处理两个子树，左子树（左右根、先外侧后内侧），右子树（右左根、先内侧后外侧）
 */

public class Mine {
    public boolean isSymmetric(TreeNode root) {
        return Compare(root.left, root.right);
    }

    public boolean Compare(TreeNode left, TreeNode right){
        if (left == null && right == null) return true;
        else if (left == null && right != null) return false;
        else if (right == null && left != null) return false;
        else if (left.val != right.val) return false;
        else {
            boolean outside = Compare(left.left, right.right);
            boolean inside = Compare(left.right, right.left);
            boolean result = inside && outside;
            return result;
        }
    }
}
